/**
 * Created by Administrator on 2016/12/5 0005.
 */
/**
 * Created by qqlai on 2016/11/22.
 */
{
    angular.module('loginModule')
        .controller('loginController', loginController);
    loginController.$inject = ['http.interfaces', '$state', '$ionicHistory'];
    function loginController(interfaces, $state, $ionicHistory) {
        let vm = this;
        let collect = {
            name: '',
            data: {},
            password: '',
            login: login,
            active: Active
        };
        collect.active();//进入控制器后调用一次
        vm.collect = collect;//输出集合，提供给模板调用


        /** Active方法
         * @desc 控制器触发时执行一次的方法
         * @constructor
         */
        function Active() {

        }

        function login() {
            if(collect.name&&collect.password){
                interfaces.login({account: collect.name, password: collect.password}).then(res=> {
                    if (res.data.resultCode == 1) {
                        collect.data = res.data.userMessage;
                        if (res.data.userMessage.mobile_user_type == 'student') {
                            $state.go("tab.studentPerson", {id: collect.data.mobile_user_id})
                        } else {
                            $ionicHistory.clearCache().then(function(){ $state.go("tab.overviews"); })
                        }
                        collect.password = '';
                    }
                });
            }

        }

    }
}